import {
	defineStore
} from 'pinia'

import {
	ref
} from 'vue'

export const useBookingStore = defineStore('booking', () => {
		// 存储预定信息数据
		const bookingData = ref({})

		// 将获取到的信息存入信息对象
		const setInfoData = (data) => {
			bookingData.value = data
		}

		// 添加游客信息
		const addVisitorData = (data) => {
			if (!bookingData.value.visitors) {
				bookingData.value.visitors = []
			}
			bookingData.value.visitors.push(data)
		}

		// 清空信息对象
		const clearInfoData = () => {
			bookingData.value = {}
		}

		return {
			bookingData,
			setInfoData,
			addVisitorData,
			clearInfoData
		}
	},
	// 持久化
	{
		persist: {
			storage: {
				getItem(key) {
					return uni.getStorageSync(key)
				},
				setItem(key, value) {
					return uni.setStorageSync(key, value)
				}
			}
		}
	})